from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2, DATE, NUMBER

# 创建对象的基类
Base = declarative_base()

# 生成结果历史类
class fklist(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_FKLIST'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    JS_YWFL = Column(VARCHAR2(200)) #结算业务分类
    JSLJ = Column(VARCHAR2(200))
    FKZH = Column(VARCHAR2(200))
    FKZHMC = Column(VARCHAR2(200)) #付款账号名称
    FKGS = Column(VARCHAR2(200))   #付款归属
    FKJE = Column(NUMBER)          #付款金额
    SKZH = Column(VARCHAR2(200))
    SKZHMC = Column(VARCHAR2(200)) #收款账号名称
    SKGS = Column(VARCHAR2(200))   #收款归属
    RQ = Column(VARCHAR2(40))
    SCRQ = Column(DATE)            #流水日期
    REMARKS = Column(VARCHAR2(400))
    FKH = Column(VARCHAR2(200))
    SKH = Column(VARCHAR2(200))
    DATA_SOURCE = Column(VARCHAR2(200))
    YT = Column(VARCHAR2(200))
    PCH = Column(VARCHAR2(200))
    BXGD = Column(NUMBER)
    JYND = Column(NUMBER)         #交易年度
    IMPORT = Column(NUMBER)
    IS_TC = Column(NUMBER)
    YWZL = Column(VARCHAR2(256))
    TCX = Column(VARCHAR2(256))
    BZ = Column(VARCHAR2(100))

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID = int(data.get('ID')) if data.get('ID') is not None else 0,
            JS_YWFL = data.get('JS_YWFL'),
            JSLJ = data.get('JSLJ'),
            FKZH = data.get('FKZH'),
            FKZHMC = data.get('FKZHMC'),
            FKGS = data.get('FKGS'),
            FKJE = data.get('FKJE'),
            SKZH = data.get('SKZH'),
            SKZHMC = data.get('SKZHMC'),
            SKGS = data.get('SKGS'),
            RQ = data.get('RQ'),
            SCRQ = data.get('SCRQ'),
            YT = data.get('YT'),
            PCH = data.get('PCH'),
            BXGD = data.get('BXGD'),
            JYND = data.get('JYND'),
            IMPORT = data.get('IMPORT'),
            IS_TC = data.get('IS_TC'),
            YWZL = data.get('YWZL'),
            TCX = data.get('TCX'),
            BZ = data.get('BZ')
        )

    def to_dict(self):
        return {
            'ID': self.ID,
            'JS_YWFL': self.JS_YWFL,
            'JSLJ': self.JSLJ,
            'FKZH': self.FKZH,
            'FKZHMC': self.FKZHMC,
            'FKGS': self.FKGS,
            'FKJE': self.FKJE,
            'SKZH': self.SKZH,
            'SKZHMC': self.SKZHMC,
            'SKGS': self.SKGS,
            'RQ': self.RQ,
            'SCRQ': self.SCRQ,
            'YT': self.YT,
            'PCH': self.PCH,
            'BXGD': self.BXGD,
            'JYND': self.JYND,
            'IMPORT': self.IMPORT,
            'IS_TC': self.IS_TC,
            'YWZL': self.YWZL,
            'TCX': self.TCX,
            'BZ': self.BZ
        }